<?php
namespace Admin\Controller;
use Think\Controller;
class EChartsOrdersController  extends IndexController {
    public function lists(){

        $this->display();
    }
    public function get_order_list(){
        $orders=D("Order_info");
        $goods=D("Goods_base");
        $manager=D("Manager");
        $res=$manager->where("username='".$_SESSION['name']."'")->find();
        if(!$res){
            $where='';
        }else{
            $where='shop_id='.$res['shop_id'];
        }
        $result=$goods->where($where)->select();

        $res=$orders->where($where)->field("goods_ids")->select();
        $str='';
        foreach($res as $v){
            $str.=$v['goods_ids'];
        }
        $arr=explode(",",rtrim($str,","));
        $temp=array();
        foreach ($result as $k=>$value) {
            $aa=0;
            foreach($arr as $vv){
                if($value['id']==$vv){
                    $aa++;

                }
            }
            $temp[$k]['value']=$aa;
            if ($_COOKIE["think_language"] == 'en-us') {
                $temp[$k]['name']=$value['en_name'];
            }

            if ($_COOKIE["think_language"] == 'zh-cn') {
                $temp[$k]['name']=$value['name'];
            }


        }
        echo json_encode($temp);


    }
    public function get_name(){
        $orders=D("Order_info");
        $goods=D("Goods_base");
        $manager=D("Manager");
        $res=$manager->where("username='".$_SESSION['name']."'")->find();
        if(!$res){
            $where='';
        }else{
            $where='shop_id='.$res['shop_id'];
        }
        $result=$goods->where($where)->select();

        $res=$orders->where($where)->field("goods_ids")->select();
        $str='';
        foreach($res as $v){
            $str.=$v['goods_ids'];
        }
        $arr=explode(",",rtrim($str,","));
        $temp=array();
        foreach ($result as $k=>$value) {
            $aa=0;
            foreach($arr as $vv){
                if($value['id']==$vv){
                    $aa++;

                }
            }

            //在英文情况下执行
            if ($_COOKIE["think_language"] == 'en-us') {
                $temp[$k]=$value['en_name'];
            }
            //当语言在中文情况下执行
            if($_COOKIE["think_language"] == 'zh-cn'){
                $temp[$k]=$value['name'];
            }


        }
        echo json_encode($temp);

    }
    public function get_tjt(){
        $orders=D("Order_info");
        $goods=D("Goods_base");
        $manager=D("Manager");
        $res=$manager->where("username='".$_SESSION['name']."'")->find();
        if(!$res){
            $where='';
        }else{
            $where='shop_id='.$res['shop_id'];
        }
        $result=$goods->where($where)->select();

        $res=$orders->where($where)->field("goods_ids,create_time")->select();
        $str='';
        $str1='';
        foreach($res as $v){
            $str.=$v['goods_ids'];
            $str1.=$v['create_time'].',';
        }
        $arr=explode(",",rtrim($str,","));
        $arr1=explode(",",rtrim($str1,","));
        $temp=array();
        foreach ($result as $k=>$value) {
            $aa=0;//"00:00-05:00","05:00-11:00","11:00-14:00","14:00-18:00","18:00-24:00"
            $bb=0;
            $cc=0;
            $dd=0;
            $ee=0;

            foreach($arr as $kk=>$vv){
                if($value['id']==$vv){
                    $h = intval(date("H",$arr1[$kk]));
                    if ($h > 0 && $h < 5) {
                        $aa++;
                    } elseif ($h >= 5 && $h < 11) {
                        $bb++;
                    } elseif ($h >= 11 && $h < 14){
                        $cc++;
                    } elseif ($h >= 14 && $h < 18){
                        $dd++;
                    } else{
                        $ee++;
                    }
//                            $temp1=strtotime(date("H:i:s", $value['create_time']));


                }
            }
            $temp2=array($aa,$bb,$cc,$dd,$ee);
            //当英文情况下执行
            if ($_COOKIE["think_language"] == 'en-us') {
                $temp[$k]['name']=$value['en_name'];
            }
            //当中文状态下执行
            if ($_COOKIE["think_language"] == 'zh-cn') {
                $temp[$k]['name']=$value['name'];
            }

            $temp[$k]['type']='bar';
            $temp[$k]['data']=$temp2;
        }
        echo json_encode($temp);


    }

}